package top.glike.ssl.auto.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.glike.ssl.auto.domain.other.AutoSslDomain;
import top.glike.ssl.auto.mapper.AutoSslConfMapper;
import top.glike.ssl.auto.service.IAutoSslConfService;

/**
 * 自动配置SSL控制器层
 */
@Slf4j
@RestController
@RequestMapping("/autoSsl")
public class AutoSslConfController {

    @Autowired
    private IAutoSslConfService autoSslConfService;
    @Autowired
    private AutoSslConfMapper autoSslConfMapper;

    @GetMapping("/testCert")
    public void testCert() {
        autoSslConfService.testCert();
    }


    @GetMapping("/syncCloudCertToLocal")
    public void syncCloudCertToLocal() {
        autoSslConfService.syncCloudCertToLocal(null);
    }

    @GetMapping("/getCloudCertInfo/{domainName}")
    public void getCloudCertInfo(@PathVariable("domainName") String domainName) {
        AutoSslDomain sslDomain = autoSslConfMapper.queryNeedAutoRenewCertByDomainName(domainName);
        autoSslConfService.getCloudCertInfo(sslDomain);
    }
}
